<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' encoding='UTF-8' doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent='yes'/>

	<!-- xml filesources -->
	<xsl:variable name="src_head" select="document(root/filehead/@src)"/>
	<xsl:variable name="src_head_ie" select="document(root/filehead_ie/@src)"/>
	<xsl:variable name="src_header" select="document(root/fileheader/@src)"/>
	<xsl:variable name="src_navbar" select="document(root/filenavbar/@src)"/>
	<xsl:variable name="src_footer" select="document(root/filefooter/@src)"/>
	
	<!-- template to load a static content -->
	<xsl:template name="Loader">
		<xsl:param name="src"/>  
		<xsl:copy-of select="$src/root/*[name() != 'namespace']"/>
	</xsl:template>

	<!-- template to load extra data content -->
	<xsl:template name="ExtraDataLoader">
		<xsl:param name="src"/>
		<xsl:copy-of select="$src/*[name() != 'namespace']"/>
	</xsl:template>
	
	<!-- template to load IE Fix content -->
	<xsl:template name="IELoader">
		<xsl:param name="src"/>
		<xsl:comment>[if IE 6]><xsl:value-of select="$src"/>&lt;![endif]</xsl:comment>
	</xsl:template>
	
	<!-- template to dinamically create menu -->
	<xsl:template name="NavLoader">
		<xsl:param name="src"/>
		<xsl:variable name="page" select="page"/>
		<!-- login -->
		<xsl:copy-of select="$src/root/linkable/a"/>
		<!-- navbar link list -->
		<ul id="nav_list">
			<xsl:if test="page = 'home'">
				<xsl:copy-of select="$src/root/not_linkable/ul/li[text()='Home']"/>
			</xsl:if>
			<xsl:if test="page != 'home'">
				<xsl:copy-of select="$src/root/linkable/ul/li[a[@accesskey='o']]"/>					
			</xsl:if>
			<xsl:if test="page = 'signup'">
				<xsl:copy-of select="$src/root/not_linkable/ul/li[text()='Sign Up']"/>
			</xsl:if>
			<xsl:if test="page != 'signup'">
				<xsl:copy-of select="$src/root/linkable/ul/li[a[@accesskey='s']]"/>
			</xsl:if>
			<xsl:if test="page = 'help'">
					<xsl:copy-of select="$src/root/not_linkable/ul/li[text()='Help']"/>
			</xsl:if>
			<xsl:if test="page != 'help'">
				<xsl:copy-of select="$src/root/linkable/ul/li[a[@accesskey='h']]"/>
			</xsl:if>
			<xsl:if test="page = 'about'">
				<xsl:copy-of select="$src/root/not_linkable/ul/li/a[text()='About']"/>
			</xsl:if>
			<xsl:if test="page != 'about'">
				<xsl:copy-of select="$src/root/linkable/ul/li[a[@accesskey='a']]"/>
			</xsl:if>
			<xsl:if test="page = 'sitemap'">
				<xsl:copy-of select="$src/root/not_linkable/ul/li/a[text()='Sitemap']"/>
			</xsl:if>
			<xsl:if test="page != 'sitemap'">
				<xsl:copy-of select="$src/root/linkable/ul/li[a[@accesskey='m']]"/>
			</xsl:if>
		</ul>
	</xsl:template>

	<!-- template to generate main content -->
	<xsl:template name="SignupContent">
		<!-- load extra tabindex params -->
		<xsl:call-template name="ExtraDataLoader">
			<xsl:with-param name="src" select="extradata/tabindex"/>
		</xsl:call-template>
		<!-- main tab page -->
		<div id="tab_wrapper">
			<!-- if not on success page, display standard form -->
			<xsl:if test="not(success)">
				<!-- signup form -->
				<form action="../cgi-bin/signup.pl" id="signup_form" method="post">
					<h1>Sign Up form</h1>
					<p id="required"><span>Note:</span> items marked with * are required</p>
					<fieldset id="personal">
						<legend>Personal details</legend>
						<ul>
							<li>
								<label for="first_name">first name<em>*</em> </label><input id="first_name" name="first_name" type="text" maxlength="32">
								<!-- first_name input value -->
								<xsl:if test="not(error/first_name)">
									<xsl:attribute name="value"><xsl:value-of select="error/input_first_name"/></xsl:attribute>
								</xsl:if>
								</input>
								<!-- first name error -->
								<xsl:if test="error/first_name = 'empty'">
									<span class="error_box" id="first_name_err">Required field</span>
								</xsl:if>
							</li>
							<li>
								<label for="last_name">last name<em>*</em> </label><input id="last_name" name="last_name" type="text" maxlength="32">
								<!-- last_name input value -->
								<xsl:if test="not(error/last_name)">
									<xsl:attribute name="value"><xsl:value-of select="error/input_last_name"/></xsl:attribute>
								</xsl:if>
								</input>
								<!-- last name error -->
								<xsl:if test="error/last_name = 'empty'">
									<span class="error_box" id="last_name_err">Required field</span>
								</xsl:if>
							</li>
							<li>
								<label for="email">email<em>*</em> </label><input id="email" name="email" type="text" maxlength="32">
								<!-- email input value -->
								<xsl:if test="error/email != 'empty' or not(error/email)">
									<xsl:attribute name="value"><xsl:value-of select="error/input_email"/></xsl:attribute>
								</xsl:if>
								</input>
								<!-- email error -->
								<!-- required -->
								<xsl:if test="error/email = 'empty'">
									<span class="error_box" id="email_err">Required field</span>
								</xsl:if>
								<!-- invalid format -->
								<xsl:if test="error/email = 'format'">
									<span class="error_box" id="email_err">Not valid email format</span>
								</xsl:if>
								<!-- already used -->
								<xsl:if test="error/email = 'present'">
									<span class="error_box" id="email_err">Email already used</span>
								</xsl:if>
							</li>
							<li>
								<label>gender</label><input type="radio" name="gender" id="male-gender" value="male" />
								<label for="male-gender" class="inner_label">male</label><input type="radio" name="gender" checked="true" value="female" id="female-gender"/>
								<label for="female-gender"  class="inner_label" >female</label>
							</li>
						</ul>
					</fieldset>
					<fieldset id="account"><legend>Account details</legend>
						<ul>
							<li>
								<label for="username">username<em>*</em> </label><input id="username" name="username" type="text" maxlength="32">								
								<!-- username input value -->
								<xsl:if test="error/username != 'empty' or not(error/username)">
									<xsl:attribute name="value"><xsl:value-of select="error/input_username"/></xsl:attribute>
								</xsl:if>
								</input>
								<!-- username error -->
								<!-- required -->
								<xsl:if test="error/username = 'empty'">
									<span class="error_box" id="username_err">Required field</span>
								</xsl:if>
								<!-- length -->
								<xsl:if test="error/username = 'length'">
									<span class="error_box" id="username_err">6 chars at least</span>
								</xsl:if>
								<!-- already used -->
								<xsl:if test="error/username = 'present'">
									<span class="error_box" id="email_err">Username already used</span>
								</xsl:if>
							</li>
							<li>
								<label for="password">password<em>*</em> </label><input id="password" name="password" type="password" maxlength="32"/>
								<!-- password error -->
								<xsl:if test="error/password = 'empty'">
									<span class="error_box" id="password_err">Required field</span>
								</xsl:if>
								<xsl:if test="error/password = 'length'">
									<span class="error_box" id="password_err">6 chars at least</span>
								</xsl:if>
							</li>
							<li>
								<label for="confirm_password">confirm password<em>*</em> </label><input id="confirm_password" name="confirm_password" type="password" maxlength="32"/>
								<!-- confirm_password error -->
								<xsl:if test="error/password = 'mismatch'">
									<span class="error_box" id="confirm_password_err">Check for typo</span>
								</xsl:if>
							</li>
						</ul>
					</fieldset>  
					<input type="submit" id="submit" value="Submit!" onclick="if(!FormChecker.check()) return false;"/>
				</form>
			</xsl:if>
			<!-- success page -->
			<xsl:if test="success">
				<form action="../cgi-bin/step2.pl" id="signup_form" method="post">
			      <h1>Sign Up complete</h1>
			      <p class="complete"><strong>Congratulation! You are now part of our community!</strong></p>
			      <p class="complete">It wasn't that difficult right? Now, what do you want to do?</p>
			      
			      
			      <input type="hidden" name="id">
			      	<xsl:attribute name="value">
			      		<xsl:value-of select="success/id" />
			      	</xsl:attribute>
			      </input>
			      <input type="image" src="../images/next_step_signup.png" title="Get to step 2!" alt="Next Step - Start subscribing RSS feeds!" />
			    </form>
			</xsl:if>
		</div>
	</xsl:template>

	
	<!-- CREATE PAGE -->
	
	<!-- create page structure -->
	<xsl:template match="root">
		<html>
			<!-- head -->
			<head>
				<!-- load common code -->
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_head"/>
				</xsl:call-template>
				<!-- load extra head params -->
				<xsl:call-template name="ExtraDataLoader">
					<xsl:with-param name="src" select="extradata/head"/>
				</xsl:call-template>
				<!-- load ie fix -->
				<xsl:call-template name="IELoader">
					<xsl:with-param name="src" select="$src_head_ie/root/common"/>
				</xsl:call-template>
				<xsl:call-template name="IELoader">
					<xsl:with-param name="src" select="extradata/IEFix"/>
				</xsl:call-template>
				<!-- pagetitle -->
				<title><xsl:value-of select="pagetitle"/></title>
			</head>
			<body>
				<!-- body onload attribute -->
				<xsl:if test="extradata/body/onload/text() != ''">
					<xsl:attribute name="onLoad"><xsl:value-of select="extradata/body/onload"/></xsl:attribute>
				</xsl:if>
				<!-- header -->			
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_header"/>
				</xsl:call-template>
				<!-- navbar -->
				<div id="navbar">
					<xsl:call-template name="NavLoader">
						<xsl:with-param name="src" select="$src_navbar"/>
					</xsl:call-template>
				</div>
				<!-- content -->
				<xsl:call-template name="SignupContent">
					<xsl:with-param name="src" select="$src_footer"/>
				</xsl:call-template>				
				<!-- footer -->
				<xsl:call-template name="Loader">
					<xsl:with-param name="src" select="$src_footer"/>
				</xsl:call-template>				
			</body>
		</html>
	</xsl:template>
	
</xsl:stylesheet>
